import { getPriceList, addPrice } from '@/api/price'
import { getStationList, addStation } from '@/api/station'
import { getSectionList, addSection } from '@/api/section'
import { getPlaceListSection, addPlace } from '@/api/place'

const apiDefines = {
  // 价牌 一口价
  price: {
    name: '价牌',
    editCols: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' },
    ],
    editRules: {
      unit1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      service1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      unit7: [{ required: true, trigger: 'blur', message: '不能为空' }],
      service7: [{ required: true, trigger: 'blur', message: '不能为空' }],
      overtimePrice: [{ required: true, trigger: 'blur', message: '不能为空' }]
    },
    getList: getPriceList,
    addItem: addPrice,
    mainName: (item) => {
      if (item.priceType === 2) {
        let ret = `${item.typeName}: [${item.period1}]:${item.price1}/[${item.period2}]:${item.price2}`
        if (item.period3) {
          ret += `/[${item.period3}]:${item.price3}`
        }
        return ret + `/${item.overtimePrice}`
      }
      return `${item.typeName}: ${item.chargePrice}/${item.overtimePrice}`
    },
    mainColName: 'priceType'
  },
  // 价牌 峰谷价
  price2: {
    name: '价牌',

    editCols6: [
      { text: '特斯拉', dataType: 'title' },
      // { displayName: '时段说明1', colName: 'desc1' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      // { displayName: 'SUM1', colName: 'price1', dataType: 'number'},
      // { displayName段说明2', colName: 'desc2' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      // { displayName: 'SUM2', colName: 'price2', dataType: 'number'},
      { displayName: '时段3', colName: 'period3', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit3', dataType: 'number' },
      { displayName: '服务费3', colName: 'service3', dataType: 'number' },
      // { displayName: 'SUM3', colName: 'price3', dataType: 'number'},
      { displayName: '时段4', colName: 'period4', dataType: 'timeRange' },
      { displayName: '电费4', colName: 'unit4', dataType: 'number' },
      { displayName: '服务费4', colName: 'service4', dataType: 'number' },
      // { displayName: 'SUM4', colName: 'price4', dataType: 'number'},
      { displayName: '时段5', colName: 'period5', dataType: 'timeRange' },
      { displayName: '电费5', colName: 'unit5', dataType: 'number' },
      { displayName: '服务费5', colName: 'service5', dataType: 'number' },
      // { displayName: 'SUM5', colName: 'price5', dataType: 'number'},
      { displayName: '时段6', colName: 'period6', dataType: 'timeRange' },
      { displayName: '电费6', colName: 'unit6', dataType: 'number' },
      { displayName: '服务费6', colName: 'service6', dataType: 'number' },
      // { displayName: 'SUM6', colName: 'price6', dataType: 'number'},
      // { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      // { displayName: '时段说明1', colName: 'desc1' },
      { displayName: '时段1', colName: 'period7', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      // { displayName: 'SUM1', colName: 'prices1', dataType: 'number'},
      // { displayName段说明2', colName: 'desc2' },
      { displayName: '时段2', colName: 'period8', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      // { displayName: 'SUM2', colName: 'prices2', dataType: 'number'},
      { displayName: '时段3', colName: 'period9', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit9', dataType: 'number' },
      { displayName: '服务费3', colName: 'service9', dataType: 'number' },
      // { displayName: 'SUM3', colName: 'prices3', dataType: 'number'},
      { displayName: '时段4', colName: 'period10', dataType: 'timeRange' },
      { displayName: '电费4', colName: 'unit10', dataType: 'number' },
      { displayName: '服务费4', colName: 'service10', dataType: 'number' },
      // { displayName: 'SUM4', colName: 'prices4', dataType: 'number'},
      { displayName: '时段5', colName: 'period11', dataType: 'timeRange' },
      { displayName: '电费5', colName: 'unit11', dataType: 'number' },
      { displayName: '服务费5', colName: 'service11', dataType: 'number' },
      // { displayName: 'SUM5', colName: 'prices5', dataType: 'number'},

      { displayName: '时段6', colName: 'period12', dataType: 'timeRange' },
      { displayName: '电费6', colName: 'unit12', dataType: 'number' },
      { displayName: '服务费6', colName: 'service12', dataType: 'number' },
      // { displayName: 'SUM6', colName: 'prices6', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' },
    ],
    editCols5: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      { displayName: '时段3', colName: 'period3', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit3', dataType: 'number' },
      { displayName: '服务费3', colName: 'service3', dataType: 'number' },
      { displayName: '时段4', colName: 'period4', dataType: 'timeRange' },
      { displayName: '电费4', colName: 'unit4', dataType: 'number' },
      { displayName: '服务费4', colName: 'service4', dataType: 'number' },
      { displayName: '时段5', colName: 'period5', dataType: 'timeRange' },
      { displayName: '电费5', colName: 'unit5', dataType: 'number' },
      { displayName: '服务费5', colName: 'service5', dataType: 'number' },
      { displayName: '时段6', colName: 'period6', dataType: 'timeRange' },
      { displayName: '电费6', colName: 'unit6', dataType: 'number' },
      { displayName: '服务费6', colName: 'service6', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      { displayName: '电费3', colName: 'unit9', dataType: 'number' },
      { displayName: '服务费3', colName: 'service9', dataType: 'number' },
      { displayName: '电费4', colName: 'unit10', dataType: 'number' },
      { displayName: '服务费4', colName: 'service10', dataType: 'number' },
      { displayName: '电费5', colName: 'unit11', dataType: 'number' },
      { displayName: '服务费5', colName: 'service11', dataType: 'number' },
      { displayName: '电费6', colName: 'unit12', dataType: 'number' },
      { displayName: '服务费6', colName: 'service12', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' }
    ],
    editCols4: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      { displayName: '时段3', colName: 'period3', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit3', dataType: 'number' },
      { displayName: '服务费3', colName: 'service3', dataType: 'number' },
      { displayName: '时段4', colName: 'period4', dataType: 'timeRange' },
      { displayName: '电费4', colName: 'unit4', dataType: 'number' },
      { displayName: '服务费4', colName: 'service4', dataType: 'number' },
      { displayName: '时段5', colName: 'period5', dataType: 'timeRange' },
      { displayName: '电费5', colName: 'unit5', dataType: 'number' },
      { displayName: '服务费5', colName: 'service5', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      { displayName: '电费3', colName: 'unit9', dataType: 'number' },
      { displayName: '服务费3', colName: 'service9', dataType: 'number' },
      { displayName: '电费4', colName: 'unit10', dataType: 'number' },
      { displayName: '服务费4', colName: 'service10', dataType: 'number' },
      { displayName: '电费5', colName: 'unit11', dataType: 'number' },
      { displayName: '服务费5', colName: 'service11', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' }
    ],
    editCols3: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      { displayName: '时段3', colName: 'period3', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit3', dataType: 'number' },
      { displayName: '服务费3', colName: 'service3', dataType: 'number' },
      { displayName: '时段4', colName: 'period4', dataType: 'timeRange' },
      { displayName: '电费4', colName: 'unit4', dataType: 'number' },
      { displayName: '服务费4', colName: 'service4', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      { displayName: '电费3', colName: 'unit9', dataType: 'number' },
      { displayName: '服务费3', colName: 'service9', dataType: 'number' },
      { displayName: '电费4', colName: 'unit10', dataType: 'number' },
      { displayName: '服务费4', colName: 'service10', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' }
    ],
    editCols: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      { displayName: '时段3', colName: 'period3', dataType: 'timeRange' },
      { displayName: '电费3', colName: 'unit3', dataType: 'number' },
      { displayName: '服务费3', colName: 'service3', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      { displayName: '电费3', colName: 'unit9', dataType: 'number' },
      { displayName: '服务费3', colName: 'service9', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' }
    ],
    editCols2: [
      { text: '特斯拉', dataType: 'title' },
      { displayName: '时段1', colName: 'period1', dataType: 'timeRange' },
      { displayName: '电费1', colName: 'unit1', dataType: 'number' },
      { displayName: '服务费1', colName: 'service1', dataType: 'number' },
      { displayName: '时段2', colName: 'period2', dataType: 'timeRange' },
      { displayName: '电费2', colName: 'unit2', dataType: 'number' },
      { displayName: '服务费2', colName: 'service2', dataType: 'number' },
      { text: '非特斯拉', dataType: 'title' },
      { displayName: '电费1', colName: 'unit7', dataType: 'number' },
      { displayName: '服务费1', colName: 'service7', dataType: 'number' },
      { displayName: '电费2', colName: 'unit8', dataType: 'number' },
      { displayName: '服务费2', colName: 'service8', dataType: 'number' },
      { displayName: '超时充电费', colName: 'overtimePrice', dataType: 'number' }
    ],
    editRules: {
      overtimePrice: [{ required: true, trigger: 'blur', message: '不能为空' }],
      period1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      unit1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      service1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      period2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      unit2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      service2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      period3: [{ required: true, message: '不能为空' }],
      unit3: [{ required: true, message: '不能为空' }],
      service3: [{ required: true, message: '不能为空' }],
      period4: [{ required: true, message: '不能为空' }],
      unit4: [{ required: true, message: '不能为空' }],
      service4: [{ required: true, message: '不能为空' }],
      period5: [{ required: true, message: '不能为空' }],
      unit5: [{ required: true, message: '不能为空' }],
      service5: [{ required: true, message: '不能为空' }],
      period6: [{ required: true, message: '不能为空' }],
      unit6: [{ required: true, message: '不能为空' }],
      service6: [{ required: true, message: '不能为空' }],

      unit7: [{ required: true, message: '不能为空' }],
      service7: [{ required: true, message: '不能为空' }],
      unit8: [{ required: true, message: '不能为空' }],
      service8: [{ required: true, message: '不能为空' }],
      unit9: [{ required: true, message: '不能为空' }],
      service9: [{ required: true, message: '不能为空' }],
      unit10: [{ required: true, message: '不能为空' }],
      service10: [{ required: true, message: '不能为空' }],
      unit11: [{ required: true, message: '不能为空' }],
      service11: [{ required: true, message: '不能为空' }],
      unit12: [{ required: true, message: '不能为空' }],
      service12: [{ required: true, message: '不能为空' }],
    },
    editRuless: {
      overtimePrice: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // desc1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // period1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // period1s: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // price1: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // desc2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // period2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // period2s: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // price2: [{ required: true, trigger: 'blur', message: '不能为空' }],
      // desc3: [{ required: true, message: '不能为空' }],
      // period3: [{ required: true, message: '不能为空' }],
      // period3s: [{ required: true, message: '不能为空' }],
      // price3: [{ required: true, message: '不能为空' }],
      // desc4: [{ required: true, message: '不能为空' }],
      // period4: [{ required: true, message: '不能为空' }],
      // period4s: [{ required: true, message: '不能为空' }],
      // price4: [{ required: true, message: '不能为空' }],
      // desc5: [{ required: true, message: '不能为空' }],
      // period5: [{ required: true, message: '不能为空' }],
      // period5s: [{ required: true, message: '不能为空' }],
      // price5: [{ required: true, message: '不能为空' }],
      // desc6: [{ required: true, message: '不能为空' }],
      // period6: [{ required: true, message: '不能为空' }],
      // period6s: [{ required: true, message: '不能为空' }],
      // price6: [{ required: true, message: '不能为空' }]
    },
    getList: getPriceList,
    addItem: addPrice,
    mainName: (item) => {
      return `${item.typeName}: ${item.chargePrice}/${item.overtimePrice}`
    },
    mainColName: 'priceType'
  },

  // 场站
  station: {
    name: '场站',
    editCols: [
      { displayName: 'ID', colName: 'id', readOnly: true },
      { displayName: '场站名称', colName: 'stationName' },
      { displayName: '场站描述', colName: 'stationDesc' },
      { displayName: '场站容量', colName: 'stationCapacity', dataType: 'number' },
      { displayName: '场站地址', colName: 'addrDesc' },
      { displayName: '详细地址', colName: 'addrDetailInfo' },
      { displayName: '省', colName: 'addrProvince' },
      { displayName: '市', colName: 'addrCity' },
      { displayName: '区/县', colName: 'addrCounty' },
      { displayName: '省编号', colName: 'provinceCode', dataType: 'number' },
      { displayName: '市编号', colName: 'cityCode', dataType: 'number' },
      { displayName: '经度', colName: 'stationLng', dataType: 'number' },
      { displayName: '纬度', colName: 'stationLat', dataType: 'number' },
      { displayName: '备注', colName: 'remark' }
    ],
    editRules: {
      stationName: [{ required: true, trigger: 'blur', message: '不能为空' }],
      stationCapacity: [{ required: true, trigger: 'blur', message: '不能为空' },
      { type: 'number', message: '请输入正确的编号' }],
      addrDesc: [{ required: true, trigger: 'blur', message: '不能为空' }],
      addrDetailInfo: [{ required: true, trigger: 'blur', message: '不能为空' }],
      addrProvince: [{ required: true, trigger: 'blur', message: '不能为空' }],
      addrCity: [{ required: true, trigger: 'blur', message: '不能为空' }],
      addrCounty: [{ required: true, trigger: 'blur', message: '不能为空' }],
      provinceCode: [{ required: true, trigger: 'blur', message: '不能为空' },
      { type: 'number', message: '请输入正确的编号' }],
      cityCode: [{ required: true, trigger: 'blur', message: '不能为空' },
      { type: 'number', message: '请输入正确的编号' }],
      stationLng: [{ required: true, trigger: 'blur', message: '不能为空' },
      { type: 'number', message: '请输入正确的坐标' }],
      stationLat: [{ required: true, trigger: 'blur', message: '不能为空' },
      { type: 'number', message: '请输入正确的坐标' }],
      stationDesc: [{ required: true, trigger: 'blur', message: '不能为空' }]
    },
    getList: getStationList,
    addItem: addStation,
    mainName: (item) => {
      return `${item.stationName}`
    },
    mainColName: 'stationName'
  },

  // 区域
  section: {
    name: '区域',
    editCols: [
      { displayName: 'ID', colName: 'id', readOnly: true },
      { displayName: '区域名称', colName: 'sectionName' },
      // { displayName: '区域状态', colName: 'sectionStatus' },
      // { displayName: '是否禁用', colName: 'sectionDisabled', dataType: 'bool' },
      { displayName: '区域说明', colName: 'sectionDesc' },
      { displayName: '备注', colName: 'remark' }
    ],
    editRules: {
      sectionName: [{ required: true, trigger: 'blur', message: '不能为空' }],
      sectionStatus: [{ required: true, trigger: 'blur', message: '不能为空' }],
      sectionDesc: [{ required: true, trigger: 'blur', message: '不能为空' }],
      remark: [{ required: true, trigger: 'blur', message: '不能为空' }]
    },
    getList: getSectionList,
    addItem: addSection,
    mainName: (item) => {
      return `${item.sectionName}`
    },
    mainColName: 'sectionName'
  },

  // 车位
  place: {
    name: '车位',
    editCols: [
      { displayName: 'ID', colName: 'id', readOnly: true },
      { displayName: '车位名称', colName: 'placeName' },
      { displayName: '车位说明', colName: 'placeDesc' },
      // { displayName: '车位状态', colName: 'placeStatus', dataType: 'select', data: { options: [
      //   { name: '状态0', value: 0 },
      //   { name: '状态1', value: 1 }
      // ] }},
      // { displayName: '是否禁用', colName: 'isDisabled', dataType: 'bool' },
      { displayName: '备注', colName: 'remark' }
    ],
    editRules: {
      placeName: [{ required: true, trigger: 'blur', message: '不能为空' }],
      placeDesc: [{ required: true, trigger: 'blur', message: '不能为空' }],
      placeStatus: [{ required: true, trigger: 'blur', message: '不能为空' }]
    },
    getList: getPlaceListSection,
    addItem: addPlace,
    mainName: (item) => {
      return `${item.placeName}`
    },
    mainColName: 'placeName'
  }
}

export default apiDefines

export function getApiDefines(name) {
  return apiDefines[name]
}

export async function getList(name, listQuery) {
  if (apiDefines[name]) {
    return await apiDefines[name].getList(listQuery)
  }
  return Promise.reject(new Error('错误的获取项目列表接口'))
}

export async function addItem(name, values) {
  if (apiDefines[name]) {
    return await apiDefines[name].addItem(values)
  }
  return Promise.reject(new Error('错误的新建项目接口'))
}

export function getMainName(name, item) {
  if (apiDefines[name]) {
    return apiDefines[name].mainName(item)
  }
  return `${item.id}`
}

export function getMainColName(name) {
  if (apiDefines[name]) {
    return apiDefines[name].mainColName
  }
  return 'id'
}
